package edu.zut.cs.software.perfect.student.service.impl;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericTreeManagerImpl;
import edu.zut.cs.software.perfect.student.dao.ClassesDao;
import edu.zut.cs.software.perfect.student.domain.Classes;
import edu.zut.cs.software.perfect.student.service.ClassesManager;

/**
 * @ClassName ClassesManagerImpl
 * @Description TODO
 * @Author jihao
 * @Date 2020年6月2日 上午10:08:29
 * @Version 1.0
 */

@Service(value = "classesManager")
@Transactional
public class ClassesManagerImpl extends GenericTreeManagerImpl<Classes, Long> implements ClassesManager {

	ClassesDao classesDao;

	@Autowired
	public void setClassesDao(ClassesDao classesDao) {
		this.classesDao = classesDao;
		this.treeDao = this.classesDao;
		this.dao = this.classesDao;
	}

	@Override
	public Classes echo(Classes classes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Classes findByName(String classname) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Classes findById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Classes> findAll() {
		return (List<Classes>) this.dao.findAll();
	}

	@Override
	public Boolean deleteClassesId(Long courseId) {
		// TODO Auto-generated method stub
		// 为空返回Optional.empty()
		Optional<Classes> classes = this.dao.findById(courseId);
		if (classes.equals(Optional.empty())) {
			return false;
		} else {
			this.dao.delete(classes.get());
			return true;
		}
	}

	@Override
	public Optional<Classes> findByCourseId(Long courseId) {
		// TODO Auto-generated method stub
		Optional<Classes> result = this.dao.findById(courseId);
		return result;
	}

}
